

function Uasit_UpdateEvent()
	totalEvents=0;
	if(TEST_PARTY_STUFF and getn(TEST_PARTY_STUFF) > 0) then
		totalEvents = getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"]);
	else
		for i=1, UDKP_NUM_BIDS_TO_DISPLAY  do
			getglobal("UdkpEventFrameListButton"..i):Hide();
		end
		FauxScrollFrame_Update(UdkpListScrollFrame,0 ,UDKP_NUM_BIDS_TO_DISPLAY,AUCTIONS_BUTTON_HEIGHT);
		return;
	end
	FauxScrollFrame_Update(UdkpListScrollFrame,totalEvents ,UDKP_NUM_BIDS_TO_DISPLAY,AUCTIONS_BUTTON_HEIGHT);
	
	local offset = FauxScrollFrame_GetOffset(UdkpListScrollFrame);
	for i=1, UDKP_NUM_BIDS_TO_DISPLAY  do
		k = offset + i;
		if ( k > totalEvents ) then
			getglobal("UdkpEventFrameListButton"..i):Hide();
		else
			getglobal("UdkpEventFrameListButton"..i):Show();
			v = TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][k];

			if ( getglobal("UdkpEventFrameListButton" .. i) ) then
				getglobal("UdkpEventFrameListButton" .. i .. "eventid"):SetText(v["eventid"]);
				getglobal("UdkpEventFrameListButton" .. i .. "EventName"):SetText(v["reason"]);
				if(v["itemname"]~="") then
					totalItems=getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Items"]);
					for j=1,totalItems,1 do
						if(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Items"][j]["name"]==v["itemname"]) then
							getglobal("UdkpEventFrameListButton" .. i .. "EventItem"):SetText("|c"..TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Items"][j]["c"]..v["itemname"].."|r");
						end
					end
				else
					getglobal("UdkpEventFrameListButton" .. i .. "EventItem"):SetText("");
				end
				getglobal("UdkpEventFrameListButton" .. i .. "EventDkp"):SetText(v["dkp"]);
				if(v["type"]==1) then
					getglobal("UdkpEventFrameListButton" .. i .. "EventMember"):SetText(getn(v["players"]));
					getglobal("UdkpEventFrameListButton" .. i .. "MemberList"):Show();
				else
					getglobal("UdkpEventFrameListButton" .. i .. "EventMember"):SetText(v["players"][1]);
					getglobal("UdkpEventFrameListButton" .. i .. "MemberList"):Hide();
					
				end
				
				
			end
		end
	end
	getglobal("UdkpRaidHeaderString"):SetText(UDKP_MESSAGE_EVENT.."|cff1eff00"..TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Notes"].."|r(|cffffffff"..totalEvents.."|r)");
	totalItems = getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Items"]);
	totalMembers = getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"]);
	getdkp=0;
	for i=1,totalItems do
		local item=TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Items"][i]
		if(UdkpRaid_RarityTable[item["cost"]]~=0) then
			--SendChatMessage("|c"..item["c"].."|Hitem:"..item["id"].."|h["..item["name"].."]|h|r,"..item["player"]..","..item["cost"],UdkpOptions.UdkpChannelLevel, this.language, nil);
			getdkp=getdkp+item["cost"];
		end
	end
	if(totalMembers==0) then
		getglobal("UdkpRaidHeaderString"):SetText(getglobal("UdkpRaidHeaderString"):GetText().."  "..UDKP_MESSAGE_DKP_TOTAL..getdkp.."  "..UDKP_MESSAGE_DKP_ADV.."0".."   "..UDKP_HEAD_EVENT_MEMBER..":"..totalMembers);
	else
		getglobal("UdkpRaidHeaderString"):SetText(getglobal("UdkpRaidHeaderString"):GetText().."  "..UDKP_MESSAGE_DKP_TOTAL..getdkp.."  "..UDKP_MESSAGE_DKP_ADV..(math.floor(getdkp/totalMembers*100)/100).."    "..UDKP_HEAD_EVENT_MEMBER..":"..totalMembers);
	end
end

function UdkpdeleteEvent()
	eventid=getglobal("currenteventid"):GetText();
	
	if(eventid=="") then
		return;
	end
	
	totalEvents = getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"]);
	for i =totalEvents ,1,-1 do
		e=TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i];
		if(e.eventid==eventid) then
			totaleventPlayers=getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i]["players"]);
			totalraidmembers=getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"]);
			dkp=e.dkp;
			for j=totaleventPlayers,1,-1 do
				for k=totalraidmembers,1,-1 do
					if(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i]["players"][j]==TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["player"]) then
					TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["dkp"]=TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["dkp"] - dkp;
					TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["ldkp"]=TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["ldkp"] - dkp;
					break;
					end
				end
			end
			if(e.itemid~="") then
				totalitems=getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Items"]);
				for j=totalitems,1,-1 do
					if(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Items"][j]["itemid"]==e.itemid) then
						TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Items"][j]["cost"]=0;

						break;
					end
				end
			end
			table.remove(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"],i);
--			Uasit_UpdateMember();
			Uasit_UpdateEvent();
			
			break;
		end
	end
end

function UdkpchangeEventDkp()

	eventid=getglobal("currenteventid"):GetText();
	newdkp=getglobal("UdkpChangeEventPoint"):GetNumber();
	
	if(eventid=="") then
		return;
	end
	if(newdkp==0) then
		UdkpRaidMessageBox(UDKP_MESSAGE_DKP_ISNULL) ;
		return;
	end
	
	totalEvents = getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"]);
	for i =totalEvents ,1,-1 do
		e=TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i];
		if(e.eventid==eventid) then
			totaleventPlayers=getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i]["players"]);
			totalraidmembers=getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"]);
			dkp=e.dkp;
			for j=totaleventPlayers,1,-1 do
				for k=totalraidmembers,1,-1 do
					if(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i]["players"][j]==TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["player"]) then
					TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["dkp"]=TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["dkp"] - dkp + newdkp;
					TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["ldkp"]=TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["ldkp"] - dkp + newdkp;
					break;
					end
				end
			end
			if(e.itemid~="") then
				totalitems=getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Items"]);
				for j=totalitems,1,-1 do
					if(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Items"][j]["itemid"]==e.itemid) then
						TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Items"][j]["cost"]= (newdkp*-1);

						break;
					end
				end
			end
			TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i]["dkp"]=newdkp;
--			Uasit_UpdateMember();
			Uasit_UpdateEvent();
			
			break;
		end
	end
	
end

function UdkpchageEventMember()
	eventid=getglobal("currenteventid"):GetText();
	if(eventid=="") then
		return;
	end
	totalEvents = getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"]);
	totalraidmembers=getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"]);
	for i =1 ,totalEvents,1 do
		e=TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i];
		if(e.eventid==eventid) then
			totaleventPlayers=getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i]["players"]);
			totalraidmembers=getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"]);
			dkp=e.dkp;
			for j=totaleventPlayers,1,-1 do
				for k=totalraidmembers,1,-1 do
					if(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i]["players"][j]==TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["player"]) then
						TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["dkp"]=TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["dkp"] - dkp;
						
						break;
					end
				end
				table.remove(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i]["players"],j);
			end
			
			for j=1,60,1 do
				if(getglobal("UdkpMemberList"..j.."Check"):GetChecked()) then
					membername=getglobal("UdkpMemberList"..j.."ButtonName"):GetText();
					for k=totalraidmembers,1,-1 do
						if(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["player"]==membername) then
							TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["dkp"]=TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][k]["dkp"] + dkp;
							
						end
					end
					table.insert(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i]["players"],1,membername);
				end
				
			end
		

			
			break;
		end
	end
--	Uasit_UpdateMember();
	Uasit_UpdateEvent();
	UdkpChangeEventMemberFrame:Hide();
end

function UdkpChangeEventMemberFrame_OnMouseUp()

	if ( UdkpChangeEventMemberFrame.isMoving ) then
		UdkpChangeEventMemberFrame:StopMovingOrSizing();
		UdkpChangeEventMemberFrame.isMoving = false;
	end
end

function UdkpChangeEventMemberFrame_OnMouseDown(button)
	if ( ( ( not UdkpChangeEventMemberFrame.isLocked ) or ( UdkpChangeEventMemberFrame.isLocked == 0 ) ) and ( arg1 == "LeftButton" ) ) then
		UdkpChangeEventMemberFrame:StartMoving();
		UdkpChangeEventMemberFrame.isMoving = true;
	end
end



function UdkpChangeEventMemberFrame_OnHide()
	if ( UdkpChangeEventMemberFrame.isMoving ) then
		UdkpChangeEventMemberFrame:StopMovingOrSizing();
		UdkpChangeEventMemberFrame.isMoving = false;
	end
end

function UdkpChangeEventMemberFrame_OnShow()
	eventid=getglobal("currenteventid"):GetText();
	if(eventid=="") then
		return;
	end
	totalEvents = getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"]);
	totalraidmembers=getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"]);
	for i =1 ,totalEvents,1 do
		e=TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i];
		if(e.eventid==eventid) then
			
			for j=1,60,1 do
				if(j>totalraidmembers) then
					getglobal("UdkpMemberList"..j):Hide();
					getglobal("UdkpMemberList"..j.."Check"):SetChecked(false);
				else
					getglobal("UdkpMemberList"..j):Show();
					getglobal("UdkpMemberList"..j.."Check"):SetChecked(false);
					getglobal("UdkpMemberList"..j.."ButtonName"):SetText(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Members"][j]["player"]);
				end
			end
			eventplayerNumber=getn(TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i]["players"]);
			
			for j=1,totalraidmembers,1 do
				if(j<=60) then
					for k=1,eventplayerNumber,1 do
						
						if(getglobal("UdkpMemberList"..j.."ButtonName"):GetText()==TEST_PARTY_STUFF[UdkpRaid_GetCurrentRaid]["Events"][i]["players"][k]) then
							getglobal("UdkpMemberList"..j.."Check"):SetChecked(true);
						end
					end
				end
			end
			
			break;
		end
	end
end
